<#if invalid?? && invalid>
<div class="row">
	<div class="col-md-12">
		<div class="alert alert-danger" role="alert">
			<strong>错误！</strong>
			无效的招标信息或者系统异常！
		</div>
	</div>
</div>
<#elseif cannotcreate?? && cannotcreate>
<div class="row">
	<div class="col-md-12">
		<div class="alert alert-danger" role="alert">
			<strong>警告！</strong>
			您无法创建此投标的合同信息！
		</div>
	</div>
</div>
<#else>
<form class="form-create-contract" action="${request.contextPath}/contract/create-by-bid" method="post" enctype="multipart/form-data">
	<input type="hidden" name="type" value="${data.type}">
	<input type="hidden" name="status" value="${data.status}">
	<input type="hidden" name="bid.id" value="${data.bid.id}">
	<input type="hidden" name="moneyType" value="${data.moneyType}">

	<fieldset>
		<legend class="text-primary">基本信息</legend>
		<div class="row">
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								合同名称
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="name" value="${data.name}" placeholder="最多100个汉字">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								建设单位
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="companyA" value="${data.companyA}" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								承建单位
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="companyB" value="${data.companyB}" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								合同编号
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="no" value="${data.no}" placeholder="最多50个字符">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								<#if data.moneyType=='TOTAL'> 合同总价 <#elseif data.moneyType=='SINGLE'> 合同单价 <#elseif data.moneyType=='DROP_POINT'> 合同降点 </#if>
							</div>
						</div>
						<#if data.moneyType=='TOTAL'>
						<input type="text" class="form-control not-empty number" name="price" value="${data.price}" placeholder="只能是数字">
						<div class="input-group-addon">元</div>
						<#else>
						<textarea rows="1" class="form-control not-empty" name="priceDes" style="resize: none;" onfocus="$(this).attr('rows', 5);" onblur="$(this).attr('rows', 1);" placeholder="最多500个汉字">${data.priceDes}</textarea>
						</#if>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								签订日期
							</div>
						</div>
						<input type="text" class="form-control not-empty datetimepicker" name="signDate" data-foot="false" data-format="yyyy-MM-dd" data-time="${.now}" readonly="readonly" placeholder="请选择日期">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								办结日期
							</div>
						</div>
						<input type="text" class="form-control not-empty datetimepicker" name="bjTime" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="请选择日期">
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								合同工期
								<small class="text-danger contract-days-helper" style="font-weight: bold; cursor: pointer;">？</small>
							</div>
						</div>
						<input type="text" class="form-control datetimepicker" name="contractStart" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="开工日期">
						<div class="input-group-addon" style="border-left: none; border-right: none;">至</div>
						<input type="text" class="form-control datetimepicker" name="contractEnd" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="竣工日期">
						<div class="input-group-addon" style="border-left: none; border-right: none;">工期天数</div>
						<input type="text" class="form-control number" name="contractDays" placeholder="工期天数">
						<div class="input-group-addon" style="border-left: none;">天</div>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								结算方式
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="jiesuanWay" placeholder="最多500个汉字"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								付款方式
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="fukuanWay" placeholder="最多500个汉字"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								工程内容
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="mainContent" placeholder="最多1000个汉字。"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								承包范围
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="chengbaoFanwei" placeholder="最多1000个汉字。"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">备注</div>
						</div>
						<textarea rows="3" class="form-control" name="remark" placeholder="最多1000个汉字"></textarea>
					</div>
				</div>
			</div>
		</div>
	</fieldset>

	<fieldset>
		<legend class="text-success">相关文件</legend>
		<div class="row">
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								合同文件
							</div>
						</div>
						<input type="file" class="hidden" name="contractFile" data-suffix=".pdf, .jpeg, .jpg">
						<input type="text" class="form-control not-empty file-show" placeholder="请选择相关文件。格式只能是[.pdf, .jpeg, .jpg]中的一个！" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">附件资料</div>
						</div>
						<input type="file" class="hidden" name="file" data-suffix=".rar, .zip">
						<input type="text" class="form-control file-show" placeholder="请选择附件资料。格式只能是[.rar, .zip]中的一个！" readonly="readonly">
					</div>
				</div>
			</div>
		</div>
	</fieldset>

	<hr style="margin-top: 5px;">
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-sm btn-primary create-contract">确定</div>
			&nbsp;
			<div class="btn btn-sm btn-default" onclick="$.suredy.closeModal();">取消</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		$.suredy.datetimepicker.init();

		$('.contract-days-helper').tooltip({
			container : 'body',
			delay : {
				"show" : 200,
				"hide" : 100
			},
			trigger : 'hover',
			placement : 'right',
			title : function() {
				var text = '【开工日期、竣工日期】与【工期天数】只能选择一类进行填写！';
				return text;
			}
		});

		// 创建合同
		$('.create-contract').on('click', function() {
			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			var form = $('form.form-create-contract');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var cStart = $('[name="contractStart"]').val();
			var cEnd = $('[name="contractEnd"]').val();
			var cDays = $('[name="contractDays"]').val();

			if (!cStart && !cEnd && !cDays) {
				alert('【开工日期、竣工日期】与【工期天数】必须选择一类进行填写！');
				return false;
			} else if (!cDays) {
				if (!cStart || !cEnd) {
					alert('开工日期与竣工日期必须同时填写！');
					return false;
				}
			} else {
				if (cStart || cEnd) {
					alert('【开工日期、竣工日期】与【工期天数】只能选择一类进行填写！');
					return false;
				}
			}

			$this.addClass('disabled');

			// 重置费用来源
			$('.money-source').val($('input[name=otherCompany]').val());

			form.ajaxSubmit({
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert('新建合同失败！\n\n' + (data.msg || ''));
						$this.removeClass('disabled');
						return false;
					}

					location.href = '${request.contextPath}/contract/view/' + data.data.id;
					//$.suredy.refreshContent('${data.bid.id}', [ 'div.suredy-tabs', '#tab3', 'div.bid-payout' ]);
					//$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('新建合同失败！\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
